
<template>
  <div @click="startUpload">
    <input
      type="file"
      name="file"
      ref="file"
      class="file"
      @change="uploadDataFile"
    />
    <slot></slot>
  </div>
</template>

<script>
import { todouplodafile } from "@/api/api";
export default {
  data() {
    return {};
  },
  methods: {
    async uploadDataFile() {
      const file = this.$refs.file.files[0];
      console.log(file);
      const data = new FormData();
      data.append("file", file);
      let res = await todouplodafile(data);
      if (res.code == 200) {
        this.$emit("getfilepath", res.path);
      }
    },
    startUpload() {
      this.$refs.file.click();
    },
  },
};
</script>

<style lang="scss">
.file {
  display: none;
}
</style>
